package cn.iocoder.yudao.module.picturebook.dal.mysql.book;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.picturebook.dal.dataobject.book.BookDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.picturebook.controller.admin.book.vo.*;
import org.apache.ibatis.annotations.Param;

/**
 * 书籍信息 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface BookMapper extends BaseMapperX<BookDO> {

    default PageResult<BookDO> selectPage(BookPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<BookDO>()
                .likeIfPresent(BookDO::getTitle, reqVO.getTitle())
                .eqIfPresent(BookDO::getAuthor, reqVO.getAuthor())
                .eqIfPresent(BookDO::getPublisher, reqVO.getPublisher())
                .eqIfPresent(BookDO::getCoverUrl, reqVO.getCoverUrl())
                .eqIfPresent(BookDO::getLanguage, reqVO.getLanguage())
                .eqIfPresent(BookDO::getLevel, reqVO.getLevel())
                .eqIfPresent(BookDO::getCategory, reqVO.getCategory())
                .betweenIfPresent(BookDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(BookDO::getId));
    }

    List<BookDO> getByGatherId(@Param("gatherId") Long gatherId);

    Long createBook(BookDO bookDO);

    void updateTotal(String level);
}